<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.gzgi.framework.config.database.*"%>
<%@ page import="org.apache.commons.lang.*"%>
<%@ include file="/pages/system/checkAdmin.jsp"%>
<%
       String contextPath = request.getContextPath();
	   String id = request.getParameter("id");
	   String host = request.getParameter("host");
	   String databaseName = request.getParameter("databaseName");
	   String port = request.getParameter("port");
	   String username = request.getParameter("username");
	   String password = request.getParameter("password");
	   String actionType = request.getParameter("actionType");
	   if(id == null){
		   id="mysql";
	   }
	   DataSourceConfig cfg = new DataSourceConfig();
	   Map dataMap = cfg.getDatabaseMap();
	   Database database = (Database) dataMap.get(id);
	   database.setHost(host);
	   database.setDatabaseName(databaseName);
	   database.setUsername(username);
	   database.setPassword(password);
	   if(StringUtils.isNotEmpty(port) && StringUtils.isNumeric(port)){
            database.setPort(Integer.parseInt(port));
	   }
       if("reconfig".equals(actionType)){
		   try{
               cfg.config(database);
%>
<font color="green" size="5">恭喜：数据库配置成功！如要配置生效，请重新启动应用服务器！</font>
<%
		   }catch(Exception ex){
%>
<font color="red" size="4">配置失败：<%=ex.getMessage()%></font>
<%
         }
	   } else {
		     try{
		        cfg.check(database);
%>
<font color="green" size="5">数据库连接成功！</font>
<%
		   }catch(Exception ex){
%>
<font color="red" size="4">测试失败：<%=ex.getMessage()%></font>
<%
         }
	   }
%>
